#include<stdio.h>
#include<stdlib.h>
#include<sys/types.h>
#include<sys/stat.h>
#include<fcntl.h>
#include<unistd.h>

int main(void)
{
	char tmpname[] = "MDY_XXXXXX";
	char* filename;
	FILE* tmpfp;
	int fileid;

	tmpfp = tmpfile();
	if (tmpfp)
	{
		char buf[1024] = {0};
		char file_path[1024] = {0};
		sprintf(buf, "/proc/self/fd/%d", tmpfp->_fileno);
		readlink(buf, file_path, sizeof(file_path) - 1);

		printf("Opend a temporary file %s OK\n", file_path);
	}
	else
	{
		perror("tmpfile");
	}

	fileid = mkstemp(tmpname);
	{
		char buf[1024] = {0};
		char file_path[1024] = {0};
		sprintf(buf, "/proc/self/fd/%d", fileid);
		readlink(buf, file_path, sizeof(file_path) - 1);
		printf("file %d-%s opened by mkstemp\n", fileid, file_path);
	}

	return 0;
}
